/**
 * TB_DOOR_TIMESEG
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-10-30 09:55:54
 *</pre>
 */
$(function() {
	timeSeg  = new TimeSeg();
	timeSeg.init();
	
	formUrl = timeSeg.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#timeSegGrid",// 列表对象
			PAGER : "#timeSegPager",// 列表分页
			FORM : '#timeSegForm',// 表单form
			FORMGET : '#timeSegFormGet'// 表单form
			
	};
	/**
	 * TB_DOOR_TIMESEG 对象
	 * @returns {TimeSeg}
	 */
	TimeSeg = function() {
		//定义属性
	};
	var dtFormatter = function (cellValue, options, rowObject) {
		   if(cellValue==null||cellValue==""){
			   return "";
		   }
		   var date = new Date(cellValue);
		   h = date.getHours() ;
		   f  = date.getMinutes();
		   if(h<10){
			   h= '0'+h;
		   }
		   if(f<10){
			   f= '0'+f;
		   }
		  
		   　　return h+":"+f

     }
	
	var cboxFormat = function (cellValue) {
		   var html ="<input type='checkbox' checked='checked' disabled='true' />"
		   if(cellValue==0){
			   html ="<input type='checkbox' disabled='true' />"   

		   }
 		   return html;
    }

	/**
	 * 方法
	 */
	TimeSeg.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
				
			}
			if ($(this.consts.FORM).length > 0){//表单
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/TimeSegment/timeSeg/listJson.htm',
						pager :this.consts.PAGER,
						colNames: ['唯一标识','时段号','时段名称','开始时间','结束时间','时区1开始时间','时区1结束时间','时区2开始时间','时区2结束时间','时区3开始时间','时区3结束时间','星期一 ','星期二 ','星期三 ','星期四 ','星期五 ','星期六 ','星期日 ','下一个链接时段','管理'],
				        colModel: [{
				                 	   name:'id',
				                	   index: 'ID',
				                	   hidden:true,
				                	   key:true
				                	 	}, {
				                 	   name:'timeseg',
				                	   index: 'TIMESEG',
				                	   hidden:true

										
				                	 					                	 	}, 
			                	 	 {
				                 	   name:'timesegms',
				                	   index: 'TIMESEGMS'

										
				                	 					                	 	},				                	 	
				                	 					                	 	
				                	 					                	 	
				                	 					                	 	{
				                 	   name:'startdate',
				                	   index: 'STARTDATE'
										
				                	 					                	 	}, {
				                 	   name:'enddata',
				                	   index: 'ENDDATA'

										
				                	 					                	 	}, {
				                 	   name:'timezone1Starttime',
				                	   index: 'TIMEZONE1_STARTTIME'

										
				                	 					                	 	}, {
				                 	   name:'timezone1Endtime',
				                	   index: 'TIMEZONE1_ENDTIME'

										
				                	 					                	 	}, {
				                 	   name:'timezone2Starttime',
				                	   index: 'TIMEZONE2_STARTTIME'
										
				                	 					                	 	}, {
				                 	   name:'timezone2Endtime',
				                	   index: 'TIMEZONE2_ENDTIME'
										
				                	 					                	 	}, {
				                 	   name:'timezone3Starttime',
				                	   index: 'TIMEZONE3_STARTTIME'
										
				                	 					                	 	}, {
				                 	   name:'timezone3Endtime',
				                	   index: 'TIMEZONE3_ENDTIME'

										
				                	 					                	 	}, {
				                 	   name:'week1',
				                	   index: 'WEEK1',
				                	   width : 60,
				                	   formatter:cboxFormat
				                	   

										
				                	 					                	 	}, {
				                 	   name:'week2',
				                	   index: 'WEEK2',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'week3',
				                	   index: 'WEEK3',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'week4',
				                	   index: 'WEEK4',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'week5',
				                	   index: 'WEEK5',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'week6',
				                	   index: 'WEEK6',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'week7',
				                	   index: 'WEEK7',
				                	   width : 60,
				                	   formatter:cboxFormat

										
				                	 					                	 	}, {
				                 	   name:'nextLinkPeriod',
				                	   index: 'NEXT_LINK_PERIOD',
				                	   hidden:true

										
				                	 					                	 	},  {
									name : '__manage',
									width : 50,
									sortable:false,
									classes:'rowOps',
									formatter : 'manage',
									formatoptions :[{
										label:'编辑',
										classes:'btn btn-primary fa fa-edit',
										action:__ctx+'/rdp/TimeSegment/timeSeg/edit.htm?id={id}'
									},{
										label:'删除',
										classes:'btn btn-primary fa fa-remove',
										action:__ctx+'/rdp/TimeSegment/timeSeg/remove.htm?id={id}'
									}
									//,{
									//	label:'明细',
									//	classes:'btn btn-primary fa fa-detail',
									//	action: __ctx+'/rdp/TimeSegment/timeSeg/get.htm?id={id}'
									//}
				                  ]
								} ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});
		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/TimeSegment/timeSeg/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();